import 'package:example/arg/demo3arg.dart';
import 'package:example/pages/hero/hero1_page.dart';
import 'package:example/router/example_routes.dart';
import 'package:example/util/widget_util.dart';
import 'package:example_package/arg/package1arg.dart';
import 'package:example_package1/arg/package1_1arg.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:riki_router/riki_router.dart';

@RikiRoute(
  name: '/',
  routeName: '路由DEMO',
  pageRouteType: PageRouteType.cupertino,
)
class RootPage extends StatefulWidget {
  const RootPage() : super();

  @override
  _RootPageState createState() => _RootPageState();
}

class _RootPageState extends State<RootPage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: buildAppBar('路由demo'),
      body: ListView(
        children: [
          buildListTile('跳转DEMO1', () {
            RikiRouterDelegate.of(context).pushNamed(RikiRoutes.demo1,routeTransitionsBuilder: (BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child){
              return ScaleTransition(
                scale: CurvedAnimation(
                  parent: animation,
                  curve: Curves.easeOut,
                ),
                child: child,
              );
            });
          }),
          buildListTile('使用URI跳转DEMO1', () {
            RikiRouterDelegate.of(context).pushUri('/demo/1');
          }),
          buildListTile('跳转DEMO2', () {
            RikiRouterDelegate.of(context).pushNamed(RikiRoutes.demo2.name, arguments: RikiRoutes.demo2.init1('测试'));
          }),
          buildListTile('使用URI跳转DEMO2', () {
            RikiRouterDelegate.of(context).pushUri('/demo/2?text=123&num=456');
          }),
          buildListTile('跳转DEMO3', () {
            Map<String, dynamic> arg = RikiRoutes.demo3.d(
                arg: Demo3Arg(
              '1',
              1,
              true,
              ['1', '2', '3'],
              {'1': 1, '2': '测试', '3': true},
            ));
            RikiRouterDelegate.of(context).pushNamed(
              RikiRoutes.demo3.name,
              arguments: arg,
            );
          }),
          buildListTile('使用URI跳转DEMO3', () {
            RikiRouterDelegate.of(context).pushUri('/demo/3?arg={\"arg1\":\"1\",\"arg2\":1,\"arg3\":true,\"arg4\":[\"1\",\"2\",\"3\"],\"arg5\":{\"1\":1,\"2\":\"测试\",\"3\":true}}');
          }),
          buildListTile('进入PACKAGE', () {
            RikiRouterDelegate.of(context).pushNamed(RikiRoutes.package1.name, arguments: RikiRoutes.package1.d(arg: Package1Arg('', 1, true)));
          }),
          buildListTile('进入PACKAGE1', () {
            RikiRouterDelegate.of(context).pushNamed(RikiRoutes.package11.name, arguments: RikiRoutes.package11.d(arg: Package1_1Arg('', 1, true)));
          }),
          buildListTile('Hero动画demo', () {
            RikiRouterDelegate.of(context).pushNamed(
              RikiRoutes.heroDemo,
              transitionMilliseconds: 1000,
              reverseTransitionMilliseconds: 1000,
            );
          }),
        ],
      ),
    );
  }
}
